import request from "@/utils/request";
import { getToken } from "@/utils/auth";
// 查询图表数据
export function querySupplierDataList(query) {
  return request({
    url: "/supplier/querySupplierDataList",
    method: "get",
    params: query
  });
}
//查询每日数据详情
export function querySupplierDayDataPageList(query) {
  return request({
    url: "/supplier/querySupplierDayDataPageList",
    method: "get",
    params: query
  });
}
/**
 * 查看总失败数量
 * */ 
 export function querySupplierDayTotalErr(query) {
  return request({
    url: "/supplier/queryFailureDetails",
    method: "get",
    params: query
  });
}

// 上传
export function commitDataOrderFile(data,type) {
  return request({
    url:type==1?"/supplier/commitDataOrderFile":"/supplier/commitUsedCarDataOrderFile",
    method: "post",
    data: data
  });
}
// 查询公司信息
export function querySupplierInfo(query) {
  return request({
    url: "/supplier/querySupplierInfo",
    method: "get",
    params: query
  });
}
// 查询资金管理列表
export function querySupplierBillPageList(query) {
  return request({
    url: "/supplier/querySupplierBillPageList",
    method: "get",
    params: query
  });
}
//查询财务概览
export function querySupplierFinanceInfo(query) {
  return request({
    url: "/supplier/querySupplierFinanceInfo",
    method: "get",
    params: query
  });
}
// 查询结算单发票信息
export function queryExternalBillInvoice(query) {
  return request({
    url: "/supplier/queryExternalBillInvoice",
    method: "get",
    params: query
  });
}
// 提交发票信息
export function submitExternalBillInvoice(data) {
  return request({
    url: "/supplier/submitExternalBillInvoice",
    method: "post",
    data: data
  });
}
// 查询供应商信息列表
export function querySupplierInfoList(query) {
  return request({
    url: "/supplier/querySupplierInfoList",
    method: "get",
    params: query
  });
}
// 下载城市;
export function downloadCity() {
  var xhr = new XMLHttpRequest();
  var formData = new FormData();
  xhr.open("get", process.env.VUE_APP_BASE_API + "/supplier/downloadCity");
  xhr.setRequestHeader("Authorization", "Bearer " + getToken());
  xhr.responseType = "blob";
  xhr.onload = function(e) {
    let blob = new Blob([xhr.response], {
      type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
    });
    let downloadElement = document.createElement("a");
    let href = window.URL.createObjectURL(blob); //创建下载的链接
    downloadElement.href = href;
    downloadElement.download = "城市表";
    document.body.appendChild(downloadElement);
    downloadElement.click(); //点击下载
    document.body.removeChild(downloadElement); //下载完成移除元素
    window.URL.revokeObjectURL(href); //释放掉blob对象
  };
  xhr.send(formData);
}
// 下载品牌
export function downloadCarSerial() {
  var xhr = new XMLHttpRequest();
  var formData = new FormData();
  xhr.open("get", process.env.VUE_APP_BASE_API + "/supplier/downloadCarSerial");
  xhr.setRequestHeader("Authorization", "Bearer " + getToken());
  xhr.responseType = "blob";
  xhr.onload = function(e) {
    let blob = new Blob([xhr.response], {
      type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
    });
    let downloadElement = document.createElement("a");
    let href = window.URL.createObjectURL(blob); //创建下载的链接
    downloadElement.href = href;
    downloadElement.download = "品牌车型表";
    document.body.appendChild(downloadElement);
    downloadElement.click(); //点击下载
    document.body.removeChild(downloadElement); //下载完成移除元素
    window.URL.revokeObjectURL(href); //释放掉blob对象
  };
  xhr.send(formData);
}
//
export function downloadExternalNeedList(query) {
  return request({
    url: "/supplier/downloadExternalNeedList",
    method: "get",
    params: query,
    responseType: "blob"
  });
}
// 查看失败文件名称
// http://localhost:8083/supplier/querySupplierUploadError?pageNum=1&pageSize=10
export function querySupplierUploadError() {
 return request({
   url: "/supplier/querySupplierUploadError",
   method: "get"
 });
}
